﻿<%@ WebHandler Language="C#" Class="FileCS" %>

using System;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using DAL;

public class FileCS : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        int v_i_hist_id = int.Parse(context.Request.QueryString["Id"]);
        SqlConnection sqlConnec = ConnectData.getConnection();
        DALichSuCuocGoi objLichSugoi = new DALichSuCuocGoi(sqlConnec);
        objLichSugoi.load_call_infor_by_id(v_i_hist_id);
        if (objLichSugoi.data.link_down_record == "NOTHING"
            || objLichSugoi.data.link_down_record == ""
            || objLichSugoi.data.link_down_record == null) return;
        byte[] bytes;
        string contentType = "audio/x-wav";
        string strFilename;
        strFilename = objLichSugoi.data.link_down_record;
        strFilename = strFilename.Replace("/var/spool/asterisk/monitor", @"\\203.162.121.70\recording");
        bytes = System.IO.File.ReadAllBytes(strFilename);
        context.Response.Clear();
        context.Response.Buffer = true;
        context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + strFilename);
        context.Response.ContentType = contentType;
        context.Response.BinaryWrite(bytes);
        context.Response.End();
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}